<template>
  <div>
    <el-dialog
        :visible.sync="addOrderShow1"
        width="60%"
    >
      <!--      <FindById :movie-id="findByPurchaseRecordBeanIdId" v-if="findByPurchaseRecordBeanIdShow2"-->
      <!--                ref="findByPurchaseRecordBeanIdRef"></FindById>-->
      <AddOrder :movie-id="addOrderId" v-if="addOrderShow2" ref="addOrderRef"></AddOrder>
    </el-dialog>
    <el-dialog
        :visible.sync="showRadisShow1"
        width="60%"
    >
      <!--      <FindById :movie-id="findByPurchaseRecordBeanIdId" v-if="findByPurchaseRecordBeanIdShow2"-->
      <!--                ref="findByPurchaseRecordBeanIdRef"></FindById>-->
      <ShowRadis :movie-id="showRadisId" v-if="showRadisShow2" ref="showRadisRef"></ShowRadis>
    </el-dialog>
    <el-button
        plain
        slot="reference"
        @click="open1">
      购买当前选中电影
    </el-button>
    <el-button
        plain
        slot="reference"
        @click="open2">
      查看购物车
    </el-button>
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-table
              :data="tableData"
              highlight-current-row
              @current-change="handleCurrentChange"
              style="width: 100%">
            <el-table-column
                prop="name"
                label="电影名"
                align="center">
            </el-table-column>
            <el-table-column
                prop="money"
                label="单价"
                align="center">
            </el-table-column>
            <el-table-column
                prop="number"
                label="库存"
                align="center">
            </el-table-column>
            <el-table-column
                prop="number"
                label="购买数量"
                align="center">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.num"
                                 size="small"
                                 @change="handleChange(scope.row,scope.row.num)"
                                 :min="0"
                                 :max="99999"
                                 :controls="false">
                </el-input-number>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import AddOrder from "./addOrder";
import ShowRadis from "./showRadis";

export default {
  name: "logMovie",
  components: {ShowRadis, AddOrder},
  data() {
    return {
      tableData: [],//从后端获取集合数据
      currentRow: '',
      money: 0,
      value: '',
      num: '',

      addOrderShow1: false,
      addOrderShow2: false,
      addOrderId: 0,

      showRadisShow1:false,
      showRadisShow2:false,
      showRadisId:0
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    open2(){
      const h = this.$createElement;
      this.showRadisShow1=true
      this.showRadisShow2=true
      this.$nextTick(() => {
        this.$refs.showRadisRef.init()
      })
    },
    open1() {
      const h = this.$createElement;
      if (this.value == '' || this.num == '') {
        this.$notify({
          title: '提示',
          message: h('i', {style: 'color: teal'}, '请选择一个电影并输入购买数量')
        });
      } else if (this.num > this.value.number) {
        this.$notify({
          title: '提示',
          message: h('i', {style: 'color: teal'}, '无法大于库存')
        });
      } else {
        this.addOrderShow1 = true
        this.addOrderShow2 = true
        this.$nextTick(() => {
          this.$refs.addOrderRef.init(this.value.money * this.num, this.value)
        })
      }
    },
    init() {
      // this.token=localStorage.getItem("token")
      // console.log(this.token)
      // this.$axios.get("api2/findByMenu/"+this.token).then(
      //     r=>{
      //       let listData=r.data;
      //       this.quanxian1=listData[0].menuAddress
      //       this.quanxian2=listData[1].menuAddress
      //     }
      // )
      this.addOrderShow1=false
      this.addOrderShow2=false
      this.$axios.get("meituan/meituan/findByAll").then(
          r => {
            let testDate = r.data;
            console.log(r.data)
            for (let i = 0; i < testDate.length; i++) {
              testDate[i].money = testDate[i].money + 100;
            }
            this.tableData = testDate;
          }
      )
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    handleChange(value, num) {
      console.log(value)
      this.value = value
      this.num = num
      // console.log(value)
      // let sumMoney = 0
      // if (this.stockIdArray.length > 0) {
      //   for (let i = 0; i < this.stockIdArray.length; i++) {
      //     if (this.stockIdArray[i] === value.stockBean.stockId) {
      //       this.stockIdArray.splice(i, 1)
      //       this.number.splice(i, 1)
      //       this.money.splice(i,1)
      //       this.thisNumber.splice(i,1)
      //     }
      //   }
      // }
      //
      // this.stockIdArray.push(value.stockBean.stockId)
      // this.number.push(num)
      // this.thisNumber.push(value.stockBean.number)
      // this.money.push(value.stockBean.productBean.productSell)
      // this.productId.push(value.stockBean.productBean.productId);
      //
      // for (let i = 0; i < this.number.length; i++) {
      //   console.log("-----")
      //   console.log(this.number[i])
      //   console.log(this.thisNumber[i])
      //   console.log("-----")
      //   if (this.number[i]>this.thisNumber[i]){
      //     this.$message.error("不能大于库存数量")
      //     this.searchSelect(this.clientId)
      //     return
      //   }else {
      //     let formData = new FormData()
      //     formData.append("ClientId", this.clientId)
      //     formData.append("StockId", value.stockBean.stockId)
      //     formData.append("number", num)
      //     this.$axios.post('drp/orderdetail/updateNumber', formData).then(
      //         r => {
      //           if (r.data == 'ok') {
      //             sumMoney += this.number[i] * this.money[i]
      //           }
      //           this.sumMoney = sumMoney
      //         }
      //     )
      //   }
      // }
    }
  }
}
</script>

<style scoped>

</style>